




export const clearStorage = function (key: string): void {
    localStorage.removeItem(key);
};

export const getStorage = function (key: string, timeout: number = 24 * 60 * 60 * 1000): null | any {
    const data = localStorage.getItem(key);
    if (data) {
        const { data: value, time } = JSON.parse(data);
        if (new Date().getTime() - time < timeout) {
            return value;
        }
        clearStorage(key);
    }
    return null;
};

export const setStorage = function (key: string, value: string): void {
    const data = {
        data: value,
        time: new Date().getTime(),
    }
    localStorage.setItem(key, JSON.stringify(data));
};